package cn.liutao.auth.api;

import cn.liutao.auth.service.AuthService;
import cn.liutao.common.entity.LoginUser;
import cn.liutao.common.utils.ServletUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author liutao
 * @Description 退出登录api
 * @date 2023/11/3
 */
@WebServlet("/auth/logout")
public class logoutServlet extends HttpServlet {
    private AuthService authService;
    @Override
    public void init() throws ServletException {
        authService = AuthService.getInstance();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String token = ServletUtils.getToken(req);
        Integer userId = LoginUser.getUserId();
        authService.logout(token,userId);
        ServletUtils.ok(resp,"退出成功");
    }

}
